﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class Mod_RemoveManage_frm_ProductRemoveOutValidate : System.Web.UI.Page
{
    private static string strTm_type = "21";//此处代表调拨出库类型

    private void ControlButtonVisible(string UserLogID, string CurrPageID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst = cls_Menu.GetCurrUserButtonPopedom(UserLogID, CurrPageID);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            int intCount = dst.Tables[0].Rows.Count - 1;

            for (int i = intCount; i >= 0; i--)
            {
                int intButtonID = Int32.Parse(dst.Tables[0].Rows[i][2].ToString());

                switch (intButtonID)
                {
                    case 0:
                        this.panAdd.Visible = true;
                        break;
                    case 1:
                        this.hidButtonEdit.Value = intButtonID.ToString();
                        break;
                    case 2:
                        this.panDelete.Visible = true;
                        break;
                    case 3:
                        this.lbtnDelete1.Enabled = true;
                        break;
                    case 4:
                        this.panAudit.Visible = true;
                        break;
                    case 5:
                        this.hidButtonOAudit.Value = intButtonID.ToString();
                        break;
                    case 6:
                        this.panRef.Visible = true;
                        break;
                    case 7:
                        this.panSearch.Visible = true;
                        break;
                }
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            if (!IsPostBack)
            {
                ////////////////按钮权限控制 Begin /////////////////////////
                string strCurrPageID = this.Page.Request.Params["PageID"];
                this.ControlButtonVisible(strUserID, strCurrPageID);
                //////////////////////  End ///////////////////////////////

                this.GetStockInInfoByMain();
            }
            else
            {
                //this.labMessage.Text = "";
                this.lblJs.Text = "";//清空Js脚本 
            }
        }
        else
        {
            //ClsMenuDAL cls_Menu = new ClsMenuDAL();
            //string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 14);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.Page.RegisterClientScriptBlock("Js", "<script>parent.window.location.href='../index.aspx'</script>");           
        }
        this.labMessage.Text = "";
    }   

    public void ChangPage(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = this.dgrdResult.CurrentPageIndex;
            int intPageCounts = this.dgrdResult.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindStockInByDataView(dst, intPageIndex);
        }
    }

    public void ChildChangPage(object sender, EventArgs e)
    {
        //获取保存的从表中的结果集和DataGrid控件
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetChildResultDataSet;
        DataGrid dgrd = cls_Property.SetOrGetChildDataGridControl;

        if (dst != null && dgrd != null)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = dgrd.CurrentPageIndex;
            int intPageCounts = dgrd.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindStockInChildByDataView(dgrd, dst, intPageIndex);
        }
    }

    public void AddStockInInfo(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsOtherStockInRDAL cls_OtherStockIn = new ClsOtherStockInRDAL();
            ClsRemoveValidateDAL cls_RemoveOutValidate = new ClsRemoveValidateDAL();
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            ImageButton ibtnAdd = (ImageButton)sender;
            int intCommandName = Int32.Parse(ibtnAdd.CommandName);

            if (intCommandName == 0)//打开主表添加面板
            {                                
                //获取系统编码
                string strCode = cls_Menu.GetSystemCode("0", "00", "", 62);
                if (strCode != "Error")
                {
                    this.panAddResult.Visible = true;
                    this.ctbAddValiOut_No.Text = strCode;
                    this.ctsAddOper.Text = strUserID;
                    this.ctsbAddVali_date.Text = System.DateTime.Today.ToShortDateString();
                    this.lblJs.Text = "<script>document.getElementById('" + this.ctsbAddVali_date.ClientID + "_txtBox').focus();</script>";
                }
                else
                {
                    this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                }
            }
            else if (intCommandName == 1)//关闭主表添加面板
            {
                this.panAddResult.Visible = false;
            }
            else if (intCommandName == 2)//保存主表添加记录
            {
                //保存主表新增记录
                string strValiOut_no = this.ctbAddValiOut_No.Text.Trim();//调拨确认单号
                DateTime dtValiOut_date = DateTime.Parse(this.ctsbAddVali_date.Text.Trim());//调拨日期
                string strOut_no = this.ctsbAddRemoOut_no.Text.Trim();//调拨出库单号
                DateTime dtOut_date = DateTime.Parse(this.ctbAddRemoOut_Date.Text.Trim());//出库日期
                string strOper = this.ctsAddOper.Text.Trim();//录入人
                string strValier = this.ctsbValier.Text.Trim();//确认人
                string strRemark = this.ctbAddRemark.Text.Trim();//备注               


                Boolean bolIsCussee = cls_RemoveOutValidate.AddRemoveOutValidate(strTm_type, strValiOut_no, dtValiOut_date, strOut_no,
                   dtOut_date, strOper,strValier, strRemark);

                if (bolIsCussee)
                {
                    //重新绑定结果
                    this.GetStockInInfoByMain();                   

                    //主表新增后直接打开从表进行新增从表记录 Begin///////////////////////////
                    this.panAddResult.Visible = false;
                    ImageButton ibtn = new ImageButton();
                    ibtn.CommandName = "0";

                    int intItems = this.dgrdResult.Items.Count - 1;

                    for (int i = intItems; i >= 0; i--)
                    {
                        string strRs_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRsVali_no")).Text.Trim();//ctbRstm_no

                        if (strRs_No == strValiOut_no)
                        {
                            ibtn.CommandArgument = i.ToString();
                            break;
                        }
                    }

                    this.OpenChildResult(ibtn, null);
                    this.AddStockInInfo(this.ibtnAdd, null);
                    //主表新增后直接打开从表进行新增从表记录 End///////////////////////////
                }
                else
                {
                    this.Page.RegisterClientScriptBlock("Js", "<script>alert('新增记录失败，请重试！')</script>");
                }
            }
            else
            {
                ClsRemoveValidateDAL cls_RemoveValidate = new ClsRemoveValidateDAL();
                int intIndex = Int32.Parse(this.ibtnAdd.CommandArgument);
                Panel panChildAddResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panChildAddResult");
                if (intCommandName == 3)//关闭从表添加面板
                {
                    panChildAddResult.Visible = false;
                }
                else if (intCommandName == 4)//保存从表添加记录
                {
                    DataGrid dgrd = new DataGrid();
                    string strVali_No = "";//主表单据号
                    int intChildCount = this.dgrdResult.Items.Count;

                    for (int i = 0; i < intChildCount; i++)
                    {
                        Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                        if (panItem.Visible)
                        {
                            strVali_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRstm_no")).Text.Trim();//主表单据号
                            dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                            break;
                        }
                    }

                    CuTextSelectBox ctsbChildAddIm_id = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAddIm_id");//商品编号
                    CuTextSelectBox ctsbChildAddIn_id = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAddIn_id");//仓库编号
                    CuTextBox ctbChildAddIm_qty = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAddIm_qty");//数量
                    CuTextBox Remark = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAddremark");
                    CuTextBox ctbChildAddBatchNo = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAddBatchNo");//批号
                    CuTextBox ctbChildAddIdentifyNo = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAddIdentifyNo");//识别码
                  
                    CuTextBox is_Start = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("is_Start");
                    Boolean bStart = Boolean.Parse(((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("is_Start")).Text.Trim());//是否启用批号
                    string str_BatchNo = ctbChildAddBatchNo.Text.Trim();
                    if (bStart)//如果启用批号，则必须需入批号。否则不允许保存
                    {
                        if (str_BatchNo.Length == 0)
                        {
                            this.labMessage.Text = "<script language='javascript'>alert('此商品批号不能为空！');</script>";
                            //this.lblJs.Text = "<script>document.getElementById('" + is_Start.ClientID + "_txtBox').focus();</script>";
                        }
                        else
                        {
                            Boolean bolIsSucceed = cls_OtherStockIn.AddChildOtherStockIn(strTm_type, strVali_No, ctsbChildAddIm_id.Text, ctsbChildAddIn_id.Text.Trim(),
                                 int.Parse(ctbChildAddIm_qty.Text), ctbChildAddBatchNo.Text.Trim(), ctbChildAddIdentifyNo.Text.Trim(), Remark.Text);

                            if (!bolIsSucceed)
                            {
                                this.Page.RegisterClientScriptBlock("Js", "<script>alert('新增记录失败，请重试！')</script>");
                            }
                            else
                            {
                                //重新绑定从表结果
                                DataSet dst = cls_RemoveValidate.GetRemoveProductChilds(strTm_type, strVali_No);                                
                                if (dst != null && dst.Tables[0].Rows.Count > 0)
                                {
                                    this.BindStockInChildByDataView(dgrd, dst, 0);
                                }
                            }
                        }
                    }
                    else
                    {
                        Boolean bolIsSucceed = cls_OtherStockIn.AddChildOtherStockIn(strTm_type, strVali_No, ctsbChildAddIm_id.Text, ctsbChildAddIn_id.Text.Trim(),
                                     int.Parse(ctbChildAddIm_qty.Text), ctbChildAddBatchNo.Text.Trim(), ctbChildAddIdentifyNo.Text.Trim(), Remark.Text);

                        if (!bolIsSucceed)
                        {
                            this.Page.RegisterClientScriptBlock("Js", "<script>alert('新增记录失败，请重试！')</script>");
                        }
                        else
                        {
                            //重新绑定从表结果                        
                            DataSet dst = cls_RemoveValidate.GetRemoveProductChilds(strTm_type, strVali_No);
                            if (dst != null && dst.Tables[0].Rows.Count > 0)
                            {
                                this.BindStockInChildByDataView(dgrd, dst, 0);
                            }
                        }
                    }
                    //this.lblJs.Text = "<script>document.getElementById('" + ctsbChildRs0.ClientID + "_txtBox').focus();</script>";
                }
                else if (intCommandName == 5)//打开从表添加面板
                {
                    panChildAddResult.Visible = false;
                    CuTextSelectBox ctsbChildAddIm_id = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAddIm_id");
                    this.lblJs.Text = "<script>document.getElementById('" + ctsbChildAddIm_id.ClientID + "_txtBox').focus();</script>";
                }
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.Page.RegisterClientScriptBlock("Js", "<script>parent.window.location.href='../index.aspx'</script>");
        }
    }

    public void UpDateStockInInfo(object sender, EventArgs e)
    {
        ClsOtherStockInRDAL cls_OtherStockIn = new ClsOtherStockInRDAL();        
        ClsRemoveValidateDAL cls_RemoveValidate = new ClsRemoveValidateDAL();
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        ImageButton ibtnUpdate = (ImageButton)sender;
        int intCommandName = Int32.Parse(ibtnUpdate.CommandName);
        int intIndex = Int32.Parse(ibtnUpdate.CommandArgument);

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            if (intCommandName == 0)//主表确认
            {
                int intCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intCount; i++)
                {
                    bool IsChecked = ((CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect")).Checked;

                    if (IsChecked)
                    {
                        string strTm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRsVali_no")).Text.Trim();//调拨出库确认单号                       
                        string strReturn = cls_RemoveValidate.CheckRemoveWhetherAudit(strTm_No, strTm_type, 0, strUserID);
                        string[] arrReValue = strReturn.Split(new char[] { '|' });
                        if (arrReValue[0] == "N")//不可以取消确认，得到返回的批号
                        {
                            if (arrReValue[1].Length > 0 && arrReValue[2].Length > 0)
                            {
                                this.labMessage.Text = "<script language='javascript'>alert('当前" + arrReValue[1] + "商品" + arrReValue[2] + "批号未入库,请确认！');</script>";
                            }
                            else
                            {
                                this.labMessage.Text = "<script language='javascript'>alert('当前" + arrReValue[1] + "商品未入库,请确认！');</script>";
                            }
                        }
                        else if (arrReValue[0] == "Q")
                        {
                            if (arrReValue[1].Length > 0 && arrReValue[2].Length > 0)
                            {
                                this.labMessage.Text = "<script language='javascript'>alert('当前" + arrReValue[1] + "商品" + arrReValue[2] + "批号库存不足,请调整！');</script>";
                            }
                            else
                            {
                                this.labMessage.Text = "<script language='javascript'>alert('当前" + arrReValue[1] + "商品库存不足,请确认！');</script>";
                            }
                        }
                        else//成功返回“0”
                        {
                            if (strReturn != "0")
                            {
                                this.labMessage.Text = "<script language='javascript'>alert('确认失败,请确认！');</script>";
                            }

                            //重新绑定结果
                            this.GetStockInInfoByMain();
                        }                        
                    }
                }
            }
            else if (intCommandName == 3)//主表取消确认
            {
                string strTm_No = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRsVali_no")).Text.Trim();//调拨确认单号
                Boolean bAudit = cls_RemoveValidate.ChkNoAuditRemOutValidate(strTm_No);
                if (bAudit)
                {
                    this.labMessage.Text = "<script language='javascript'>alert('该单据已调拨入库，请联系系统管理员处理！');</script>";
                }
                else
                {
                    string strReturn = cls_RemoveValidate.CheckRemoveWhetherAudit(strTm_No, strTm_type, 1, strUserID);
                    if (strReturn != "0")
                    {
                        this.labMessage.Text = "<script language='javascript'>alert('取消确认失败,请确认！');</script>";
                    }
                    else
                    {
                        //重新绑定结果
                        this.GetStockInInfoByMain();
                    }
                }
            }
            else if (intCommandName == 1 || intCommandName == 2 || intCommandName == 4)//主表编辑
            {
                CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
                ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
                ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
                ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
                ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");

                CuTextBox ctsVali_No = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRsVali_no");//调拨确认单号
                CuTextSelectBox ctsbRsVali_date = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRsVali_date"); //调拨日期                                               
                CuTextSelectBox ctsbRswk_id = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRswk_id");//录入人                 
                CuTextBox Remark = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRsremark");//备注

                if (intCommandName == 1)//取消编辑
                {    
                    ctsbRswk_id.Visible = false;
                    chkRsSelect.Visible = ibtnRsEdit.Visible = true;
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = ibtnRsOAudit.Visible = false;
                    Remark.ReadOnly = true;                    
                }
                else if (intCommandName == 2)//编辑
                {                    
                    ctsbRswk_id.Visible = true;
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = true;
                    ctsbRsVali_date.ReadOnly = Remark.ReadOnly = false;
                    chkRsSelect.Visible = ibtnRsEdit.Visible = ibtnRsOAudit.Visible = false;                    
                }
                else//保存编辑
                {
                    chkRsSelect.Visible = ibtnRsEdit.Visible = true;
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = false;
                    
                    Boolean bolIsSucceed = cls_RemoveValidate.UpDateRemoveProduct(strTm_type, ctsVali_No.Text,
                        DateTime.Parse(ctsbRsVali_date.Text), Remark.Text);

                    if (bolIsSucceed)
                    {
                        this.GetStockInInfoByMain();//重新绑定结果
                    }
                    else
                    {
                        this.Page.RegisterClientScriptBlock("Js", "<script>alert('修改记录失败，请重试！')</script>");
                    }
                }
            }
            else//－－－－－－－－－－－－－－－－－－－－－－－从表相关操作
            {                
                //从表修改记录的代码
                DataGrid dgrd = new DataGrid();
                string strVali_No = "";//主表单据号
                string strOut_No = "";//调拨出库单号
                int intChildCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intChildCount; i++)
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        strVali_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRsVali_no")).Text.Trim();//调拨确认单号
                        strOut_No = ((CuTextSelectBox)this.dgrdResult.Items[i].FindControl("ctsbtm_no")).Text.Trim();//调拨出库单号
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        break;
                    }
                }

                CheckBox chkChildRsSelect = (CheckBox)dgrd.Items[intIndex].FindControl("chkChildRsSelect");
                ImageButton ibtnChildRsCancel = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsCancel");
                ImageButton ibtnChildRsEdit = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsEdit");
                ImageButton ibtnChildRsServer = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsServer");

                CuTextBox ctbChildRsQty = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRsQty");//数量                
                CuTextBox Remark = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRsRemark");//备注
                TextBox txtChildRsIm_id = (TextBox)dgrd.Items[intIndex].FindControl("txtChildRsIm_no");//商品编号                                                                
                CuTextBox ctbChildRsBatchNo = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRsBatchNo");//批号
                //CuTextBox ctbChildRsIdentifyNo = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRsIdentifyNo");//识别码
                int ihidQty = int.Parse(((Label)dgrd.Items[intIndex].FindControl("hidQty")).Text.Trim());//当前未修改数量

                if (intCommandName == 6)//从表编辑
                {
                    chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;                    
                    ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    ctbChildRsQty.ReadOnly = Remark.ReadOnly = false;                    
                }
                else if (intCommandName == 5)//从表取消编辑
                {
                    chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = true;
                    ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = false;
                    ctbChildRsQty.ReadOnly = Remark.ReadOnly = true;
                    ctbChildRsQty.Text = ihidQty.ToString();
                }
                else if (intCommandName == 7)//从表保存编辑
                {
                    chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = true;
                    ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = false;
                   
                    //检查是否可以修改正确 
                    string sCurQty = "";                    
                    if (ctbChildRsQty.Text.Trim().Length > 0)
                    {
                        sCurQty = ctbChildRsQty.Text.Trim();//当前修改后数量
                    }
                    int iSpare_qty = cls_RemoveValidate.ChkIsAudit(strTm_type, strOut_No, txtChildRsIm_id.Text.Trim(), ctbChildRsBatchNo.Text.Trim());//当前商品修改的数量幅度

                    if (sCurQty.Length == 0)
                    {
                        this.labMessage.Text = "<script language='javascript'>alert('修改的当前商品数量不能为空！');</script>";
                        ctbChildRsQty.ReadOnly = false;
                        this.lblJs.Text = "<script>document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').focus();document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').select();</script>";
                        chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;
                        ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    }
                    else if (int.Parse(sCurQty) <= 0)
                    {
                        this.labMessage.Text = "<script language='javascript'>alert('修改的当前商品数量应大于“0”！');</script>";
                        ctbChildRsQty.ReadOnly = false;
                        this.lblJs.Text = "<script>document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').focus();document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').select();</script>";
                        chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;
                        ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    }
                    else if (iSpare_qty == 0 && int.Parse(sCurQty) > ihidQty)
                    {
                        this.labMessage.Text = "<script language='javascript'>alert('当前商品数量只能改小,请调整！');</script>";
                        ctbChildRsQty.ReadOnly = false;
                        this.lblJs.Text = "<script>document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').focus();document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').select();</script>";
                        chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;
                        ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    }
                    else if (((int.Parse(sCurQty)) > ihidQty) && ((int.Parse(sCurQty)) - ihidQty) > iSpare_qty)
                    {
                        this.labMessage.Text = "<script language='javascript'>alert('当前商品数量修改过大,请调整！');</script>";
                        ctbChildRsQty.ReadOnly = false;
                        this.lblJs.Text = "<script>document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').focus();document.getElementById('" + ctbChildRsQty.ClientID + "_txtBox').select();</script>";
                        chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;
                        ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    }
                    else
                    {                       
                            Boolean bolIsCussee = cls_RemoveValidate.UpDateRemoveProductD(strTm_type, strVali_No, txtChildRsIm_id.Text,
                               ctbChildRsBatchNo.Text.Trim(), decimal.Parse(ctbChildRsQty.Text), Remark.Text);
                            if (!bolIsCussee)
                            {
                                this.Page.RegisterClientScriptBlock("Js", "<script>alert('修改明细失败，请重试！')</script>");
                            }
                            else
                            {
                                //修改后重新绑定明细表                        
                                DataSet dst = cls_RemoveValidate.GetRemoveProductChilds(strTm_type, strVali_No);
                                if (dst != null && dst.Tables[0].Rows.Count > 0)
                                {
                                    this.BindStockInChildByDataView(dgrd, dst, 0);
                                }
                                else
                                {
                                    this.BindStockInChildByDataView(dgrd, dst, 0);
                                }
                            }                        
                    }
                }
            }
        }
    }

    public void lbtnDelete_Click(object sender, EventArgs e)
    {
        int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    public void OpenChildResult(object sender, ImageClickEventArgs e)
    {
        ImageButton ibtnOpen = (ImageButton)sender;
        int intCommandName = Int32.Parse(ibtnOpen.CommandName);
        int intIndex = Int32.Parse(ibtnOpen.CommandArgument);
        int intCount = this.dgrdResult.Items.Count;
        bool is_audit = bool.Parse(this.dgrdResult.Items[intIndex].Cells[1].Text);

        CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
        ImageButton ibtnOpenChild = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnOpenChild");
        ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
        ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
        ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
        ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");
        Panel panShowChildResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panShowChildResult");

        //显示从表信息
        CuTextBox ctbRsVali_no = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRsVali_no");
        ClsRemoveValidateDAL cls_RemoveValidate = new ClsRemoveValidateDAL();
        DataSet dst = cls_RemoveValidate.GetRemoveProductChilds(strTm_type, ctbRsVali_no.Text.Trim());

        if (dst == null || dst.Tables[0].Rows.Count <= 0)
        {
            ibtnOpen.Attributes.Add("OnClick", "return confirm('单据录入未完成，您要删除此单据吗？');");
        }

        if (intCommandName == 0)//展开
        {
            string strDm_No = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRsVali_no")).Text.Trim();//主单号
            string strDm_Date = ((CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRsVali_date")).Text.Trim();//主单日期
            this.labbodNoAndDate.Text = strDm_No + "*" + strDm_Date;

            for (int i = 0; i < intCount; i++)
            {
                //找到展开的项
                Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                if (i == intIndex)
                {
                    panItem.Visible = true;
                }
                else
                {
                    panItem.Visible = false;
                }
            }

            //主表展开后则不可操作
            this.ibtnAdd.ImageUrl = "../App_Images/b_18_3.gif";
            this.ibtnAdd.Enabled = false;
            this.ibtnAdd.CommandName = "5";
            this.ibtnRef.CommandName = "1";
            this.ibtnDelete0.CommandName = "-1";//删除从表用（假删除）
            this.lbtnDelete0.CommandName = "-2";//删除从表用（假删除）
            this.lbtnDelete1.CommandName = "-3";//删除从表用（真删除）
            this.ibtnAdd.CommandArgument = intIndex.ToString();
            panShowChildResult.Visible = true;
            ibtnOpenChild.CommandName = "1";
            ibtnOpenChild.ImageUrl = "../App_Images/ico/10.gif";
            ibtnRsEdit.ImageUrl = "../App_Images/ico/14.gif";
            ibtnRsServer.ImageUrl = "../App_Images/ico/16.gif";
            ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
            ibtnRsCancel.ImageUrl = "../App_Images/ico/18.gif";
            this.ibtnAudit.ImageUrl = "../App_Images/b_21_3.gif";
            this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = false;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;

            //如果主表确认后则从表不可操作
            if (is_audit)
            {
                this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = false;
                this.ibtnAdd.ImageUrl = "../App_Images/b_18_3.gif";
                this.ibtnDelete0.ImageUrl = "../App_Images/b_19_5.gif";
                this.imgDelete.ImageUrl = "../App_Images/b_19_6.gif";
                this.imgDelete.Attributes.Add("OnMouseOver", "");
                this.imgDelete.Attributes.Add("OnMouseOut", "");
                this.imgDelete.Attributes.Add("OnClick", "");
            }
            
            //绑定从表信息
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                DataGrid dgrd = (DataGrid)this.dgrdResult.Items[intIndex].FindControl("dgrdChildResult");                
                this.BindStockInChildByDataView(dgrd, dst, 0);
            }
        }
        else//收缩
        {
            //收缩后都可操作
            this.ibtnAdd.ImageUrl = "../App_Images/b_18_1.gif";
            this.ibtnAdd.CommandName = "0";
            this.ibtnRef.CommandName = "0";
            this.ibtnDelete0.CommandName = "0";//恢复删除主表用
            this.lbtnDelete0.CommandName = "0";//恢复删除主表用
            this.lbtnDelete1.CommandName = "1";//恢复删除主表用
            panShowChildResult.Visible = false;
            ibtnOpenChild.CommandName = "0";
            ibtnOpenChild.ImageUrl = "../App_Images/ico/9.gif";
            ibtnRsEdit.ImageUrl = "../App_Images/ico/12.gif";
            ibtnRsServer.ImageUrl = "../App_Images/ico/11.gif";
            ibtnRsOAudit.ImageUrl = "../App_Images/ico/8.gif";
            ibtnRsCancel.ImageUrl = "../App_Images/ico/4.gif";
            this.ibtnAudit.ImageUrl = "../App_Images/b_21_1.gif";
            this.ibtnAdd.ImageUrl = "../App_Images/b_18_1.gif";
            this.ibtnDelete0.ImageUrl = "../App_Images/b_19_1.gif";
            this.imgDelete.ImageUrl = "../App_Images/b_19_4.gif";
            this.imgDelete.Attributes.Add("OnMouseOver", "ChangImage(this, '../App_Images/b_19_3.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_2.gif')");
            this.imgDelete.Attributes.Add("OnMouseOut", "ChangImage(this, '../App_Images/b_19_4.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_1.gif')");
            this.imgDelete.Attributes.Add("OnClick", "ChildMenuVisible()");
            this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = true;

            if (dst == null || dst.Tables[0].Rows.Count <= 0)
            {
                Boolean bolIsSucceed = cls_RemoveValidate.DeleteRemoveProduct(strTm_type, ctbRsVali_no.Text.Trim(), 1);
                this.GetStockInInfoByMain();//重新绑定数据
            }
            else
            {
                //重新绑定
                ClsPropertyDAL cls_Property = new ClsPropertyDAL();
                dst = cls_Property.SetOrGetCorporationDataSet;
                this.BindStockInByDataView(dst, this.dgrdResult.CurrentPageIndex);
            }
        }
    }

    private void GetStockInInfoByMain()
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsRemoveValidateDAL cls_RemoveValidate = new ClsRemoveValidateDAL();

            DataSet dst = cls_RemoveValidate.GetRemoveProductMains(strUserID,strTm_type);

            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                cls_Property.SetOrGetCorporationDataSet = dst;
                this.BindStockInByDataView(dst, 0);
            }
            else
            {
                this.dgrdResult.CurrentPageIndex = 0;
                this.dgrdResult.DataSource = null;
                this.dgrdResult.DataBind();
                this.lblRsCounts.Text = "共0条记录";
                this.lblPageCounts.Text = "共0页";
                this.lblCurrPage.Text = "当前第0页";
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = false;
                this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = false;
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.Page.RegisterClientScriptBlock("Js", "<script>parent.window.location.href='../index.aspx'</script>");
        }
    }

    private void BindStockInByDataView(DataSet dst, int CurrPageIndex)
    {
        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.dgrdResult.CurrentPageIndex = CurrPageIndex;
            this.dgrdResult.DataSource = dst;
            this.dgrdResult.DataBind();

            this.lblRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条记录";
            this.lblPageCounts.Text = "共" + this.dgrdResult.PageCount + "页";
            this.lblCurrPage.Text = "当前第" + (this.dgrdResult.CurrentPageIndex + 1) + "页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = true;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = true;

            if (this.dgrdResult.PageCount == 1)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
                this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == this.dgrdResult.PageCount - 1)
            {
                this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == 0)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = false;
            }
        }
        else
        {
            this.dgrdResult.DataSource = null;
            this.dgrdResult.DataBind();
        }
    }

    private void BindStockInChildByDataView(DataGrid dgrd, DataSet dst, int CurrPageIndex)
    {
        if (dgrd != null && dst != null)
        {
            dgrd.CurrentPageIndex = CurrPageIndex;
            dgrd.DataSource = dst;
            dgrd.DataBind();

            int intIndex = Int32.Parse(dgrd.ToolTip);
            int intItems = dgrd.Items.Count;

            Label lblChildRsCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildRsCounts");
            Label lblChildPageCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildPageCounts");
            Label lblChildCurrPage = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildCurrPage");
            LinkButton lbtnChildFirst = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildFirst");
            LinkButton lbtnChildPrev = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildPrev");
            LinkButton lbtnChildNext = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildNext");
            LinkButton lbtnChildEnd = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildEnd");

            lblChildRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条明细记录";
            lblChildPageCounts.Text = "共" + dgrd.PageCount + "页";
            lblChildCurrPage.Text = "当前第" + (dgrd.CurrentPageIndex + 1) + "页";
            lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = true;
            lblChildRsCounts.Enabled = lblChildPageCounts.Enabled = lblChildCurrPage.Enabled = true;

            if (dgrd.PageCount == 1)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == dgrd.PageCount - 1)
            {
                lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == 0)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = false;
            }

            //判断从表中的记录是否可操作
            //for (int i = 0; i < intItems; i++)
            //{
            //    CheckBox chkChildRsSelect = (CheckBox)dgrd.Items[i].FindControl("chkChildRsSelect");
            //    ImageButton ibtnChildRsEdit = (ImageButton)dgrd.Items[i].FindControl("ibtnChildRsEdit");

                //if (!this.ibtnAdd.Enabled)
                //{
                //    chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = false;
                //    ibtnChildRsEdit.ImageUrl = "../App_Images/ico/14.gif";                
                //}
                //else
                //{
                //    chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = true;
                //    ibtnChildRsEdit.ImageUrl = "../App_Images/ico/12.gif";
                //}
            //}

            //保存从表中的结果集和DataGrid控件用于从表中的翻页
            ClsPropertyDAL cls_Property = new ClsPropertyDAL();
            cls_Property.SetOrGetChildResultDataSet = dst;
            cls_Property.SetOrGetChildDataGridControl = dgrd;
        }
    }

    private void DeleteStockCheckInfo(int CommandName)
    {
        ClsRemoveValidateDAL cls_RemoveValidate = new ClsRemoveValidateDAL();

        int intCount = this.dgrdResult.Items.Count;

        if (CommandName == 0 || CommandName == 1)//删除主表(0:假删除;1:真删除)
        {
            for (int i = 0; i < intCount; i++)
            {
                CheckBox chkBox = (CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect");

                if (chkBox.Checked)
                {
                    CuTextBox txtBox = (CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRsVali_no");//调拨出库确认单号

                    Boolean bolIsCussee = cls_RemoveValidate.DeleteRemoveProduct(strTm_type, txtBox.Text.Trim(), CommandName);

                    if (!bolIsCussee)
                    {
                        this.Page.RegisterClientScriptBlock("Js", "<script>alert('删除其他入库信息失败，请重试！')</script>");
                    }
                }
            }
            //重新绑定结果
            this.GetStockInInfoByMain();
        }
        else if (CommandName == -1 || CommandName == -2 || CommandName == -3)//删除从表:-1,-2假删除,-3真删除，
        {
            DataGrid dgrd = new DataGrid();
            string strVali_No = "";//主表单据号
            int intChildCount = this.dgrdResult.Items.Count;

            for (int i = 0; i < intChildCount; i++)
            {
                Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                if (panItem.Visible)
                {
                    strVali_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRsVali_no")).Text.Trim();//主表编号
                    dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                    break;
                }
            }

            int intChildItem = dgrd.Items.Count;

            for (int j = 0; j < intChildItem; j++)
            {
                CheckBox checkBox = (CheckBox)dgrd.Items[j].FindControl("chkChildRsSelect");

                if (checkBox.Checked)
                {
                    string strChildDm_No = ((TextBox)dgrd.Items[j].FindControl("txtChildRsIm_no")).Text.Trim();//明细产品编号
                    string strBatch_no = ((CuTextBox)dgrd.Items[j].FindControl("ctbChildRsBatchNo")).Text.Trim();//批号

                    Boolean bolIsCussee = cls_RemoveValidate.DeleteChildRemoveProduct(strTm_type, strVali_No, strChildDm_No,strBatch_no,CommandName);

                    if (!bolIsCussee)
                    {
                        this.Page.RegisterClientScriptBlock("Js", "<script>alert('删除明细失败，请重试！')</script>");
                    }
                }
            }

            DataSet dst = cls_RemoveValidate.GetRemoveProductChilds(strTm_type, strVali_No);
            //DataSet dst = cls_OtherStockIn.GetOtherStockInChilds(strTm_type, strTm_No);

            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                this.BindStockInChildByDataView(dgrd, dst, 0);
            }
            else
            {
                dgrd.DataSource = null;
                dgrd.DataBind();
            }
        }
    }

    protected void ibtnDelete0_Click(object sender, ImageClickEventArgs e)
    {
        int intCommandName = Int32.Parse(((ImageButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    protected void txtGo_TextChanged(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strIndex = this.txtGo.Text.Trim();
            this.txtGo.Text = String.Empty;

            if (strIndex != "")
            {
                try
                {
                    int intIndex = Int32.Parse(strIndex) - 1;

                    if (intIndex >= 0 && intIndex < this.dgrdResult.PageCount)
                    {
                        this.BindStockInByDataView(dst, intIndex);
                    }
                    else
                    {
                        this.Page.RegisterClientScriptBlock("Js", "<script>alert('请输入正确的页码数！')</script>");
                    }
                }
                catch
                {
                    this.Page.RegisterClientScriptBlock("Js", "<script>alert('请输入数字类型的页码！')</script>");
                }
            }
            else
            {
                this.Page.RegisterClientScriptBlock("Js", "<script>alert('请输入要跳转的页码！')</script>");
            }
        }
    }

    protected void ibtnRef_Click(object sender, ImageClickEventArgs e)
    {
        int intCommand = Int32.Parse(((ImageButton)sender).CommandName);

        if (intCommand == 0)//刷新主表
        {
            this.GetStockInInfoByMain();
        }
        else//刷新从表
        {

        }
    }

    protected void dgrdResult_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            bool Is_audit = bool.Parse(e.Item.Cells[1].Text.Trim());
            bool bIs_visible = bool.Parse(e.Item.Cells[2].Text.Trim());//是否作废

            CheckBox chkRsSelect = (CheckBox)e.Item.FindControl("chkRsSelect");
            CuTextBox ctbRsremark = (CuTextBox)e.Item.FindControl("ctbRsremark");
            ImageButton ibtnRsEdit = (ImageButton)e.Item.FindControl("ibtnRsEdit");
            ImageButton ibtnRsCancel = (ImageButton)e.Item.FindControl("ibtnRsCancel");
            ImageButton ibtnRsServer = (ImageButton)e.Item.FindControl("ibtnRsServer");
            ImageButton ibtnRsOAudit = (ImageButton)e.Item.FindControl("ibtnRsOAudit");

            //修改按回车提交
            if (ctbRsremark.ReadOnly)
            {
                ctbRsremark.Attributes.Add("onkeydown", "if(event.keyCode == 13){document.getElementById('" + ibtnRsServer.ClientID + "').click();}");
            }

            if (bIs_visible)//是否作废
            {
                chkRsSelect.Enabled = ibtnRsEdit.Enabled = false;
                ibtnRsEdit.ImageUrl = "../App_Images/ico/14.gif";
            }

            string strButtonEdit = this.hidButtonEdit.Value;
            string strButtonOAudit = this.hidButtonOAudit.Value;

            if (!Is_audit)
            {
                if (strButtonEdit.Trim() == "1")
                {
                    if (this.panAudit.Visible || this.panDelete.Visible)
                    {
                        chkRsSelect.Visible = true;
                    }

                    ibtnRsEdit.Visible = true;
                }
                else if (this.panAudit.Visible || this.panDelete.Visible)
                {
                    chkRsSelect.Visible = true;
                }                
            }
            else
            {
                ibtnRsOAudit.Visible = true;

                if (strButtonOAudit.Trim() != "5")
                {
                    ibtnRsOAudit.Enabled = false;
                    ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
                }
            }
        }
    }    

    //在主DataGrid中给子DataGrid注册事件 
    protected void dgrdResult_ItemCreated(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataGrid dgrdChildResult = (DataGrid)e.Item.FindControl("dgrdChildResult");

            //子DataGrid注册事件
            dgrdChildResult.ItemDataBound += new DataGridItemEventHandler(dgrdChildResult_ItemDataBound);
        }
    }

    protected void dgrdChildResult_ItemDataBound(object sender, DataGridItemEventArgs e)
    {   
        //明细GRID dgrdChildResult_ItemDataBound事件
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            int iIndex = int.Parse(((DataGrid)sender).ToolTip);
            bool Is_audit = bool.Parse(this.dgrdResult.Items[iIndex].Cells[1].Text.Trim());//是否确认
            bool Is_visible = bool.Parse(this.dgrdResult.Items[iIndex].Cells[2].Text.Trim());//是否作废
            CheckBox chkChildRsSelect = (CheckBox)e.Item.FindControl("chkChildRsSelect");
            ImageButton ibtnChildRsEdit = (ImageButton)e.Item.FindControl("ibtnChildRsEdit");
            if (Is_audit || Is_visible)//是否作废
            {
                chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = false;
                ibtnChildRsEdit.ImageUrl = "../App_Images/ico/14.gif";
            }
            else
            {
                string strbodNoAndDate = this.labbodNoAndDate.Text.ToString();
                string[] arrBodAndDate = strbodNoAndDate.Split(new Char[] { '*' });
                string strbodNo = arrBodAndDate[0];//单据号
                string strDate = arrBodAndDate[1];//单据日期
                string ctbChildIm_no = ((TextBox)e.Item.FindControl("txtChildRsIm_no")).Text.Trim();//商品ID
                string ctbChildBatch_no = ((CuTextBox)e.Item.FindControl("ctbChildRsBatchNo")).Text.Trim();//识别码
                decimal ctbChildQty = decimal.Parse(((CuTextBox)e.Item.FindControl("ctbChildRsQty")).Text.Trim());//商品数量

                Label labGenIdentifyNo = (Label)e.Item.FindControl("labGenIdentifyNo");
                labGenIdentifyNo.Text = "<input type='button'style='width:50px; height:20px;' onclick=\"ModalDialog('../WebCustomUserControls/SelectIdentifyNo.aspx?ParBod_No=" + strbodNo + "&ParBod_Date=" + strDate +
                    "&ParIm_No=" + ctbChildIm_no + "&ParBatch_no=" + ctbChildBatch_no + "&ParQty=" + ctbChildQty + "', 440, 400)\" value='选择...' />";
            }
        }
    }

    //根据订单状态进行相关查询
    public void lbtnQuery_Click(object sender, EventArgs e)
    {
        int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

        this.QueryOrderByStatu(intCommandName);
    }

    private void QueryOrderByStatu(int CommandName)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsRemoveProductDAL cls_RemoveProduct = new ClsRemoveProductDAL();
            DataSet dst = cls_RemoveProduct.GetOrderInformationByStatu(strUserID, "tbhTranAffirmM", int.Parse(strTm_type), CommandName);
            cls_Property.SetOrGetCorporationDataSet = dst;
            this.BindStockInByDataView(dst, 0);
        }
    }
}
